<template>
  <div class="admin_all">
    <admin_top></admin_top>
    <div>

      <div class="t_table_box">
        <div>{{$route.query.name}}接口渠道快递配置</div>
        <div style="margin: 20px 0;"><el-button @click="add()" type="danger">添加配置</el-button></div>
        <el-table :data="tableData">
          <el-table-column prop="up_info" label="上游返回信息">
          </el-table-column>
          <el-table-column prop="our_info" label="对应物流信息">
          </el-table-column>


          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button @click="shanchu(scope.row)" type="text" size="small">删除</el-button>
              <el-button @click="bianji(scope.row)" type="text" size="small">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <el-dialog title="提单频率设置" :visible.sync="tidanlog" width="500px">
      <!-- <el-input v-model="all.our_info" style="width: 100%; margin-bottom: 20px;" placeholder="请输入我的物流信息名称"></el-input> -->
      <el-input v-model="all.up_info" style="width: 100%; margin-bottom: 20px;" placeholder="请输入上游返回的物流识别信息"></el-input>
      <el-select v-model="all.tracking_code" style="width: 100%; margin-bottom: 20px;" placeholder="请选择我的物流信息名称编码">
        <el-option v-for="item in wuliulist" :key="item.company" :label="item.company"  :value="item.tracking_code*1"></el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="danger" @click="tidango">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>
<script>
  import admin_top from './top.vue';
  import axios from "axios";

  export default {
    components: {
      admin_top,
    },
    data() {
      return {
        tableData: [],
        tidanlog: false,
        all: {},
        wuliulist: []
      };
    },
    mounted() {

      this.getqdlist()
      this.getwllist()


    },
    destroyed() {



    },
    methods: {
      add:function(){
        this.all = {}
        this.tidanlog = true
      },
      shanchu:function(item) {
        axios.get('/api/plan-market/admin/upstream/channel/tracking/del', {
            params: {
              id: item.id
            }
          })
          .then((response) => {
            if (response.data.msg.code == 0) {
            	this.$message.success('已删除');
              this.getqdlist()
            } else {
            	this.$message.error(response.data.msg.info);
            }

          })
      },
      bianji:function(item) {
        axios.get('/api/plan-market/admin/upstream/channel/tracking/get', {
            params: {
              id: item.id
            }
          })
          .then((response) => {
            if (response.data.msg.code == 0) {
            	this.all = response.data.data[0]
            	this.tidanlog = true
            } else {
            	this.$message.error(response.data.msg.info);
            }
          })
      },
      tidango:function() {
        this.all.channel_config_id = this.$route.query.id
        this.wuliulist.forEach(item=>{
          if(item.tracking_code == this.all.tracking_code){
            this.all.our_info = item.company
          }
        })
       
        if(this.all.id){
          axios.post('/api/plan-market/admin/upstream/channel/tracking/edit', this.all)
            .then((response) => {
              if (response.data.msg.code == 0) {
              	this.$message.success('修改成功');
              	this.getqdlist()
              	this.tidanlog = false
              } else {
              	this.$message.error(response.data.msg.info);
              }
            })
        }else{
          axios.post('/api/plan-market/admin/upstream/channel/tracking/add', this.all)
            .then((response) => {
              if (response.data.msg.code == 0) {
              	this.$message.success('添加成功');
              	this.getqdlist()
              	this.tidanlog = false
              } else {
              	this.$message.error(response.data.msg.info);
              }
            })
        }

      },

      getqdlist() {
        axios.get('/api/plan-market/admin/upstream/channel/tracking/list', {
            params: {
              id: this.$route.query.id
            }
          })
          .then((response) => {
            this.tableData = response.data.data
          })
      },
      getwllist() {
        axios.get('/api/plan-market/admin/upstream/channel/tracking/companies', {
            params: {
              id: this.$route.query.id
            }
          })
          .then((response) => {
            this.wuliulist = response.data.data
          })
      },

    },
  }
</script>
<style scoped>
  .t_btn_box {
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
  }

  .t_table_box {
    padding: 20px;
  }
</style>
<style lang="scss" scoped>
  .admin_all {
    background: #EAEAEA;
    min-height: 100vh;
    padding: 0px;

    .logo {
      height: 30px;
    }

    .el-input {
      // width: 180px;
      // margin-right: 10px;
    }

    .flex {
      display: flex;
    }



    .zu {
      margin-top: 20px;

      .tit {
        background: #ccc;
        line-height: 45px;
        padding-left: 20px;
      }

      .con {
        background: #FFFFFF;
        padding: 20px;
        line-height: 30px;
        font-size: 14px;
      }

      .lli {
        margin-right: 30px;
        color: #666;
      }
    }
  }
</style>
